/******************************************************************************
 *   Copyright (C) 2009-2024 by the GIMLi development team                    *
 *   Thomas Günther thomas@resistivity.net                                    *
 *   Carsten Rücker carsten@resistivity.net                                   *
 *                                                                            *
 *   Licensed under the Apache License, Version 2.0 (the "License");          *
 *   you may not use this file except in compliance with the License.         *
 *   You may obtain a copy of the License at                                  *
 *                                                                            *
 *       http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                            *
 *   Unless required by applicable law or agreed to in writing, software      *
 *   distributed under the License is distributed on an "AS IS" BASIS,        *
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 *   See the License for the specific language governing permissions and      *
 *   limitations under the License.                                           *
 *                                                                            *
 ******************************************************************************/

#include "gimli.h"
#include "datacontainer.h"
#include "dc1dmodelling.h"
#include "meshgenerators.h"

namespace GIMLI {

DC1dModelling::DC1dModelling(size_t nlayers,
                             const RVector & am, const RVector & bm,
                             const RVector & an, const RVector & bn,
                             bool verbose)
: ModellingBase(verbose), nlayers_(nlayers), am_(am), an_(an), bm_(bm), bn_(bn){
    init_();
    setMesh(createMesh1DBlock(nlayers));
    k_ = (2.0 * PI) / (1.0 / am_ - 1.0 / an_ - 1.0 / bm_ + 1.0 / bn_);
    meanrhoa_ = 100.0; //*** hack
}

DC1dModelling::DC1dModelling(size_t nlayers,
                             const RVector & ab2, const RVector & mn2,
                             bool verbose)
: ModellingBase(verbose), nlayers_(nlayers){
    init_();
    setMesh(createMesh1DBlock(nlayers));
    am_ = ab2 - mn2;
    an_ = ab2 + mn2;
    bm_ = ab2 + mn2;
    bn_ = ab2 - mn2;
    k_ = (2.0 * PI) / (1.0 / am_ - 1.0 / an_ - 1.0 / bm_ + 1.0 / bn_);
    meanrhoa_ = 100.0; //*** hack
}

DC1dModelling::DC1dModelling(size_t nlayers, DataContainer & data, bool verbose)
: ModellingBase(verbose), nlayers_ (nlayers),
am_(RVector(data.size(), 9e9)), an_(RVector(data.size(), 9e9)),
bm_(RVector(data.size(), 9e9)), bn_(RVector(data.size(), 9e9)){
    init_();
    setMesh(createMesh1DBlock(nlayers));
    setData(data);
    R3Vector spos(data.sensorPositions());
    for (Index i = 0 ; i < data.size() ; i++){
        int ia = (int) data("a")[i];
        int ib = (int) data("b")[i];
        int im = (int) data("m")[i];
        int in = (int) data("n")[i];
        if (ia >= 0 && im >= 0) am_[i] = spos[ia].distance(spos[im]);
        if (ia >= 0 && in >= 0) an_[i] = spos[ia].distance(spos[in]);
        if (ib >= 0 && im >= 0) bm_[i] = spos[ib].distance(spos[im]);
        if (ib >= 0 && in >= 0) bn_[i] = spos[ib].distance(spos[in]);
    }
    k_ = (2.0 * PI) / (1.0 / am_ - 1.0 / an_ - 1.0 / bm_ + 1.0 / bn_);
    meanrhoa_ = 100.0; //*** hack

    if (data.allNonZero("rhoa")) meanrhoa_ = mean(data("rhoa"));
}

RVector DC1dModelling::createDefaultStartModel() {
    RVector mod(nlayers_ * 2 - 1, meanrhoa_);
    for (size_t i = 0; i < nlayers_ -1; i++) mod[i] = std::pow(2.0, 1.0 + i);
    return mod;
}

RVector DC1dModelling::response(const RVector & model) {

    if (model.size() < (nlayers_ * 2 - 1)){
        throwError(WHERE_AM_I + " model vector to small: nlayers_ * 2 - 1 = " + str(nlayers_ * 2 - 1) + " > " + str(model.size()));
    }
    if (model.size() > (nlayers_ * 2 - 1)){
        throwError(WHERE_AM_I + " model vector to large: nlayers_ * 2 - 1 = " + str(nlayers_ * 2 - 1) + " < " + str(model.size()));
    }

    RVector rho(nlayers_);
    RVector thk(nlayers_ - 1);
    for (size_t i = 0 ; i < nlayers_ -1 ; i++) thk[i] = model[i];
    for (size_t i = 0 ; i < nlayers_ ; i++) rho[i] = model[nlayers_ + i -1];
    return rhoa(rho, thk);
}

RVector DC1dModelling::rhoa(const RVector & rho, const RVector & thk) {
    tmp_ = pot1d(am_, rho, thk);
    tmp_ -= pot1d(an_, rho, thk);
    tmp_ -= pot1d(bm_, rho, thk);
    tmp_ += pot1d(bn_, rho, thk);
    return tmp_ * k_ + rho[0];
}

RVector DC1dModelling::kern1d(const RVector & lam, const RVector & rho, const RVector & h) {
    size_t nr = rho.size();
    size_t nl = lam.size();
    RVector z(nl, rho[nr - 1]);
    RVector p(nl, 0.0);
    RVector th(nl);
    for (int i = nr - 2; i >= 0; i--) {
        p = (z - rho[i]) / (z + rho[i]);
        th = tanh(lam * h[i]);
        z = rho[i] * (z + th * rho[i]) / (z * th + rho[i]);
    }

    RVector ehl(exp(-2.0 * lam * h[0]) * p);
    return ehl / (1.0 - ehl) * rho[0] / 2.0 / PI ;
}

RVector DC1dModelling::pot1d(const RVector & R, const RVector & rho, const RVector & thk) {
    RVector z0(R.size());
    double rabs;
    for (size_t i = 0; i < R.size(); i++) {
        rabs = std::fabs(R[i]);
        z0[i] = sum(myw_ * kern1d(myx_ / rabs, rho, thk) * 2.0) / rabs;
    }
    return z0;
}

void DC1dModelling::init_() {

    double myx[801] = { 8.917099801327442e-14, 9.854919374005225e-14,
                        1.0891370292130841e-13, 1.2036825704856076e-13, 1.3302749714952345e-13, 1.4701812115404443e-13, 1.624801519295721e-13, 1.795683386770759e-13, 1.9845370571306282e-13, 2.1932526413842005e-13,
                        2.423919035250416e-13, 2.6788448255287407e-13, 2.9605813952117967e-13, 3.2719484585839035e-13, 3.6160622818693727e-13, 3.996366871872296e-13, 4.4166684447542096e-13, 4.881173519924753e-13,
                        5.39453102030178e-13, 5.961878800294478e-13, 6.58889506717719e-13, 7.281855210496322e-13, 8.047694608278158e-13, 8.894078038623212e-13, 9.829476391381672e-13, 1.0863251447666186e-12,
                        1.2005749575703847e-12, 1.3268405280766938e-12, 1.4663855645544968e-12, 1.6206066806315702e-12, 1.7910473730731204e-12, 1.9794134696161976e-12,
                        2.1875902014670364e-12, 2.4176610713286156e-12, 2.671928705796e-12, 2.9529379008172425e-12, 3.2635010908665675e-12, 3.606726496733882e-12,
                        3.986049233643149e-12, 4.405265691040131e-12, 4.868571528133974e-12, 5.380603665464783e-12, 5.94648669276291e-12, 6.571884157565408e-12,
                        7.263055247903366e-12, 8.026917436359513e-12, 8.871115712458867e-12, 9.804099096293469e-12, 1.083520519915528e-11, 1.1974753677488471e-11,
                        1.3234149515479672e-11, 1.4625997169973058e-11, 1.6164226720110948e-11, 1.786423328424793e-11, 1.974303109946983e-11, 2.1819423805797136e-11,
                        2.4114192639334462e-11, 2.6650304417866294e-11, 2.945314140048878e-11, 3.255075532179006e-11, 3.597414814303849e-11, 3.9757582330231206e-11,
                        4.393892376436977e-11, 4.856002071592443e-11, 5.366712267639067e-11, 5.931134323874509e-11, 6.554917165946376e-11, 7.244303822198779e-11,
                        8.006193905998349e-11, 8.84821266938385e-11, 9.778787319151528e-11, 1.0807231359173195e-10, 1.194383780307337e-10, 1.3199982190169224e-10,
                        1.458823643569152e-10, 1.6122494654737812e-10, 1.781811221924631e-10, 1.9692059439719362e-10, 2.176309140979487e-10, 2.405193571352724e-10,
                        2.6581499874015355e-10, 2.9377100619593265e-10, 3.2466717262156566e-10, 3.588127172352005e-10, 3.965493801240443e-10, 4.38254842494019e-10,
                        4.843465066302134e-10, 5.352856733992456e-10, 5.915821591033856e-10, 6.537993978934625e-10, 7.225600808072236e-10, 7.985523878705335e-10,
                        8.825368756343782e-10, 9.753540890804595e-10, 1.0779329740778886e-09, 1.1913001745856734e-09, 1.316590307650528e-09, 1.4550573190356333e-09,
                        1.6080870331313015e-09, 1.7772110227512649e-09, 1.9641219376281762e-09, 2.1706904450210516e-09, 2.398983951981952e-09, 2.6512872966606394e-09,
                        2.930125615732741e-09, 3.238289616816326e-09, 3.5788635088117363e-09, 3.9552558697009004e-09, 4.371233760741438e-09, 4.830960428481882e-09,
                        5.339036971932446e-09, 5.900548391910407e-09, 6.521114483437412e-09, 7.206946080536927e-09, 7.964907216348686e-09, 8.802583820679428e-09,
                        9.728359642538127e-09, 1.0751500157513941e-08, 1.1882245299770154e-08, 1.313191194674703e-08, 1.4513007182274982e-08, 1.603935347167331e-08,
                        1.772622700162902e-08, 1.9590510569407677e-08, 2.1650862551562963e-08, 2.39279036432405e-08, 2.6444423237025737e-08, 2.9225607506844726e-08,
                        3.229929147965813e-08, 3.569623761776672e-08, 3.9450443699873716e-08, 4.359948308228109e-08, 4.818488074566826e-08, 5.325252889105579e-08,
                        5.885314624437808e-08, 6.504278566653969e-08, 7.188339514928724e-08, 7.944343781153234e-08, 8.779857710125682e-08, 9.703243406073154e-08,
                        1.0723742423401342e-07, 1.1851568259277232e-07, 1.3098008573741623e-07, 1.4475538160404734e-07, 1.5997943798373573e-07, 1.7680462234971138e-07,
                        1.953993268022487e-07, 2.1594965339340473e-07, 2.38661276698907e-07, 2.637615022784373e-07, 2.9150154162607256e-07, 3.2215902637935327e-07,
                        3.5604078695002664e-07, 3.93485923385937e-07, 4.3486919919827997e-07, 4.806047921207848e-07, 5.311504393396836e-07, 5.870120186813218e-07,
                        6.487486116074757e-07, 7.169780986905357e-07, 7.923833435699517e-07, 8.757190272810549e-07, 9.678192013565165e-07, 1.0696056352944216e-06,
                        1.1820970419372223e-06, 1.3064192730922673e-06, 1.4438165874351013e-06, 1.5956641034684996e-06, 1.763481562170637e-06, 1.9489485370736003e-06,
                        2.153921243999821e-06, 2.3804511186939235e-06, 2.630805348281166e-06, 2.9074895620382204e-06, 3.213272908573143e-06, 3.551215770395387e-06,
                        3.9247003932525885e-06, 4.337464736782819e-06, 4.793639885271016e-06, 5.297791392929011e-06, 5.854964977496619e-06, 6.4707370194807025e-06,
                        7.151270372445568e-06, 7.903376042922848e-06, 8.734581357254124e-06, 9.653205297602978e-06, 1.0668441761124589e-05, 1.1790451575578641e-05,
                        1.3030464192308714e-05, 1.4400890074365673e-05, 1.5915444904593194e-05, 1.7589286856791647e-05, 1.943916830381635e-05, 2.1483603480955747e-05,
                        2.3743053782621043e-05, 2.6240132546858776e-05, 2.8999831377238596e-05, 3.2049770267221755e-05, 3.5420474030339066e-05, 3.9145677802784465e-05,
                        4.326266467599681e-05, 4.781263883837029e-05, 5.284113796062106e-05, 5.839848895210154e-05, 6.454031164942463e-05, 7.132807547848303e-05,
                        7.882971466112418e-05, 8.712030812367597e-05, 9.628283091207627e-05, .00010640898463402168, .00011760011523947924, .00012996822732501724,
                        .00014363710511345378, .00015874355132796403, .00017543875635971472, .0001938898114321158, .00021428138090594562, .00023681755046234149,
                        .00026172386966089197, .00028924960931543914, .0003196702562801663, .00035329027061462893, .0003904461327223635, .00043150971095986065,
                        .0004768919834200666, .0005270471511392716, .0005824771838937434, .0006437368440819663, .0007114392389731867, .0007862619568910369,
                        .0008689538487452225, .0009603425227831252, .00106134262757131, .001172965006105805, .0012963268126685603, .001432662693682991,
                        .0015833371444703617, .001749858165577584, .0019338923553535471, .0021372815898255564, .00236206145681369, .002610481628777888,
                        .0028850283782960702, .0031884494615157647, .003523781618621182, .003894380966549664, .00430395658813802, .004756607653870228,
                        .0052568644477534125, .0058097337079228714, .006420748735760156, .0070960247750331065, .00784232021531088, .008667104232198337,
                        .009578631541355968, .01058602501446873, .011699366984012178, .01292980015062466, .014289639103000504, .015792493566432742,
                        .01745340461351823, .019288995200267688, .0213176365342366, .02355963193974523, .026037420060372587, .02877579943244326,
                        .03180217667711402, .03514684079505005, .038843266308924096, .04292844828769052, .0474432726056699, .052432925142121424,
                        .05794734401671005, .06404171938699284, .07077704581006589, .07822073269659269, .08644727896684318, .0955390186609277,
                        .10558694496554391, .11669162090437306, .12896418580662142, .1425274676267822, .15751721224808804, .1740834420729361,
                        .19239195749751564, .21262599629790035, .2349880675352998, .25970197833480957, .2870150738223435, .31720071263778915,
                        .3505610028001551, .38742982530616715, .4281761757235046, .4732078572224654, .5229755620071621, .5779773819945832,
                        .6387637938859128, .705943168522378, .7801878596651082, .8622409331375622, .9529236036780429, 1.0531434539328173,
                        1.1639035178482904, 1.286312319371871, 1.4215949669322265, 1.571105414736209, 1.7363400135976372, 1.9189524869191834,
                        2.120770481712021, 2.3438138603014083, 2.590314915787735, 2.8627407135861755, 3.1638177826465683, 3.496559403471568,
                        3.864295766040712, 4.270707299471052, 4.719861506988793, 5.216253674868715, 5.764851862770128, 6.3711466257477705,
                        7.041205965572229, 7.781736061331188, 8.600148387123763, 9.50463388858437, 10.504244960619703, 11.608986046819572,
                        12.82991376729097, 14.179247577028352, 15.670492062326328, 17.31857209921834, 19.13998222665243, 21.152951729381048,
                        23.377627082769912, 25.83627358549495, 28.55349819813506, 31.556495817904278, 34.87532145432361, 38.54319102985816,
                        42.59681381603341, 47.07675983216308, 52.02786588373844, 57.499684304247886, 63.546978891585546, 70.2302730025474,
                        77.6164552909287, 85.77944915165314, 94.80095257095584, 104.7712557872892, 115.79014494637693, 127.96790079449971,
                        141.42640240527066, 156.30034698636896, 172.7385979744677, 190.90567491054267, 210.9834000067356, 233.1727178841656,
                        257.6957066942373, 284.79780075142304, 314.7502469223756, 347.85281935573863, 384.4368197225841, 424.86839299489054,
                        469.55219194748827, 518.9354270590384, 573.5123423448158, 633.8291619169353, 700.4895567788577, 774.1606865676937,
                        855.5798767120917, 945.5619978329519, 1045.007621242487, 1154.912032164608, 1276.3751908839718, 1410.612741518219,
                        1558.9681785928965, 1722.9262931862318, 1904.1280332173003, 2104.386926604341, 2325.7072316617105, 2570.303996390746,
                        2840.6252274246667, 3139.3763905017645, 3469.547487675848, 3834.442982261774, 4237.7148710149695, 4683.3992345424385,
                        5175.956631754053, 5720.316742635364, 6321.927706141823, 6986.810647004632, 7721.61993717082, 8533.7097949943,
                        9431.207888724997, 10423.096680944496, 11519.303328070666, 12730.799034675721, 14069.708856989137, 15549.433054535755,
                        17184.781204437102, 18992.120420636886, 20989.539161478522, 23197.02826507598, 25636.68102434077, 28332.914304083228,
                        31312.71291320231, 34605.899677722984, 38245.43391766287, 42267.74131498499, 46713.078474065944, 51625.935823323234,
                        57055.48289037661, 63056.060407206925, 69687.72417046638, 77016.84610007683, 85116.77851171278, 94068.58825143118,
                        103961.86803991429, 114895.63314653141, 126979.31236743495, 140333.84322573253, 155092.88235486683, 171404.1431791266,
                        189430.87427924512, 209353.49323906592, 231371.3923253624, 255704.93407266162, 282597.6567455564, 312318.7117515133,
                        345165.55739862355, 381466.9359583295, 421586.16382857127, 465924.7677264125, 514926.50330238225, 569081.7963961768,
                        628932.6513833016, 695078.0757370347, 768180.0750965532, 848970.2788418777, 938257.2624866166, 1036934.640173478,
                        1145990.0082649642, 1266514.8295397097, 1399715.3569188234, 1546924.706050559, 1709616.1975797976, 1889418.1026362628,
                        2088129.9391192668, 2307740.4818776865, 2550447.6670371005, 2818680.5896832864, 3115123.815062286, 3442744.246611701,
                        3804820.8197275074, 4204977.318451588, 4647218.643520417, 5135970.894757725, 5676125.668969201, 6273089.016687442,
                        6932835.547742722, 7661968.22716631, 8467784.459883833, 9358349.12559652, 10342575.29480794, 11430313.433829404,
                        12632449.991557652, 13961016.35471448, 15429309.262008933, 17052023.882367507, 18845400.88912397, 20827389.002136763,
                        23017824.624610133, 25438630.37248463, 28114034.483345896, 31070813.300769802, 34338559.26096881, 37949977.063839935,
                        41941210.99259376, 46352206.65788929, 51227110.78693166, 56614713.05875617, 62568934.40773492, 69149366.68241139,
                        76421869.0607502, 84459227.19092624, 93341881.65455566, 103158733.04307374, 114008031.70473446, 125998361.06711893,
                        139249724.37657478, 153894745.73104006, 170079997.4265919, 187967466.90225038, 207736177.964714, 229583982.5187891,
                        253729540.73575363, 280414509.4778453, 309905960.88136274, 342499055.3043714, 378519995.3907742, 418329290.81601185,
                        462325366.38906646, 510948549.6218648, 564685477.675017, 624073967.7860842, 689708399.9252589, 762245665.5498843,
                        842411741.9949487, 931008958.2982632, 1028924025.1791439, 1137136909.5373254, 1256730642.2910707, 1388902157.714621,
                        1534974272.7587159, 1696408926.2472496, 1874821810.4523966, 2071998541.485923, 2289912530.345401, 2530744733.4747562,
                        2796905480.5094066, 3091058597.6653914, 3416148068.2074847, 3775427496.8232164, 4172492672.7921586, 4611317557.853623,
                        5096294058.951443, 5632275983.914835, 6224627619.99858, 6879277421.472865, 7602777343.586241, 8402368416.73594,
                        9286053217.133884, 10262675959.279177, 11342011011.829447, 12534860722.767656, 13853163532.931507, 15310113459.941998,
                        16920292148.366428, 18699814807.7183, 20666491498.890625, 22840005383.23152, 25242109718.238716, 27896845571.47211,
                        30830782431.6384, 34073284124.964363, 37656802698.23926, 41617203209.80661, 45994122679.122765, 50831366787.37008,
                        56177348299.437775, 62085571595.14507, 68615168159.05784, 75831488388.2609, 83806755641.0971, 92620789072.81276,
                        102361802492.4914, 113127287236.50484, 125024987894.57556, 138173980653.84482, 152705865053.37646, 168766081076.57605,
                        186515364763.42874, 206131356910.81287, 227810380961.30206, 251769407874.16525, 278248227643.65344, 307511849197.8583,
                        339853152697.13715, 375595820777.19836, 415097578073.71277, 458753771450.703, 507001326764.8393, 560323121766.2689,
                        619252818901.4403, 684380206386.2375, 756357101004.6794, 835903871710.377, 923816649321.1458, 1020975294463.8193,
                        1128352203515.134, 1247022040671.5007, 1378172493549.4902, 1523116159962.6948, 1683303684841.8264, 1860338278776.762,
                        2055991763486.9844, 2272222304808.8804, 2511194010677.5947, 2775298590246.6255, 3067179290916.914, 3389757352845.2603,
                        3746261245697.6733, 4140258980258.9175, 4575693818283.692, 5056923737985.654, 5588765050148.142, 6176540601381.315,
                        6826133046960.102, 7544043726415.414, 8337457731125.354, 9214315815124.713, 10183393868840.34, 11254390751152.201,
                        12438025358832.957, 13746143904869.607, 15191838479344.713, 16789578079474.348, 18555353420195.434, 20506836974615.496,
                        22663559846063.445, 25047107241936.324, 27681334505709.973, 30592605869234.598, 33810058314828.45, 37365893187990.14,
                        41295698479287.66, 45638805000929.47, 50438680022752.68, 55743362307269.414, 61605942897748.39, 68085096471220.516,
                        75245668574367.81, 83159324619549.98, 91905267136338.88, 101571028457055.28, 112253346769771.53, 124059134306612.45,
                        137106547357308.97, 151526168817059.44, 167462315104035.16, 185074480526599.94, 204538933555956.03, 226050480980249.84,
                        249824417596384.47, 276098680952710.22, 305136232707982.1, 337227690440025.06, 372694236244132.8, 411890831231430.6,
                        455209768098981.9, 503084597326954.5, 555994466297547.9, 614468914763040.8, 679093174657616.6, 750514027295264.4,
                        829446276574559.0, 916679902976333.0, 1013087969953849.6, 1119635361845290.2, 1237388440760519.5, 1367525719091497.5,
                        1511349654460410.5, 1670299685153324.8, 1845966636502365.2, 2040108642400334.5, 2254668741295641.0, 2491794322774168.5,
                        2753858619356014.5, 3043484458604222.0, 3363570513264593.5, 3717320312156808.5, 4108274302167593.5, 4540345282233150.0,
                        5017857563946046.0, 5545590250719085.0, 6128825068658573.0, 6773399227854440.0, 7485763843140775.0, 8273048499021379.0,
                        9143132604947816.0, 10104724255097566.0, 11167447381907442.0, 12341938075624136.0, 13639951033870320.0, 15074477206609342.0,
                        16659873813938872.0, 18412008037975264.0, 20348415826945330.0, 22488477400850210.0, 24853611215221080.0, 27467488324221096.0,
                        30356269288511564.0, 33548865998935916.0, 37077231036440890.0, 40976677464246270.0, 45286232252850760.0, 50049026875070080.0,
                        55312728980313970.0, 61130019468443070.0, 67559119737921450.0, 74664374385141260.0, 82516895186770450.0, 91195272810315090.0,
                        100786363375935070.0, 111386157741688000.0, 123100742212300240.0, 136047360286561500.0, 150355586069667600.0, 166168621094416580.0,
                        183644727530280800.0, 202958812124392600.0, 224304176727057900.0, 247894452921644900.0, 273965740121274720.0, 302778968531103500.0,
                        334622510625517300.0, 369815067276781100.0, 408708857420487600.0, 451693143181049300.0, 499198125737875200.0, 551699250923370200.0,
                        609721967644628100.0, 673846986752704000.0, 744716092991994800.0, 823038568197672300.0, 909598290026688100.0, 1005261577268834200.0,
                        1110985860256371200.0, 1227829263148597000.0, 1356961193994081000.0, 1499674048559465700.0, 1657396145060688100.0, 1831706019251760000.0,
                        2024348222941158000.0, 2237250784052685300.0, 2472544502976968700.0, 2732584278337953000.0, 3019972675609836500.0, 3337585974467093500.0,
                        3688602955558203000.0, 4076536714810807000.0, 4505269823676544000.0, 4979093187211118000.0, 5502748988894313000.0, 6081478151996170000.0,
                        6721072792498601000.0, 7427934188538936000.0, 8209136846553068000.0, 9072499305313681000.0, 10026662386494198000.0, 11081175674916358000.0,
                        12246593094004847000.0, 13534578533000223000.0, 14958022583082810000.0, 16531171550741900000.0, 18269770039599454000.0, 20191218527695090000.0,
                        22314747517318810000.0, 24661610000341512000.0, 27255294165301002000.0, 30121758475087553000.0, 33289691467965430000.0, 36790798882106413000.0,
                        40660120977274060000.0, 44936383229520880000.0, 49662383908768730000.0, 54885422418279210000.0, 60657772682979370000.0, 67037206324472250000.0,
                        74087570858843620000.0, 81879428704062800000.0, 90490763392378630000.0, 100007760055721310000.0, 110525667995470610000.0,
                        122149753969478480000.0, 134996355737163020000.0, 149194046406907200000.0, 164884921238942420000.0, 182226019782472860000.0, 201390897580266700000.0,
                        222571363170862070000.0, 245979397772890050000.0, 271849276864359830000.0, 300439914890385500000.0, 332037456565976800000.0, 366958140708523600000.0,
                        405551465262171750000.0, 448203685190718500000.0, 495341678247114960000.0, 547437217309496100000.0, 605011692042713700000.0, 6.68641327141347e+20,
                        7.38962949380122e+20, 816680361190317800000.0, 9.02571384551055e+20, 9.97495645693098e+20, 1102403178527102100000.0, 1218343932902309600000.0,
                        1346478282857540700000.0, 1.48808864003459e+21, 1644592288484969700000.0, 1817555569325064300000.0, 2.008709557204488e+21,
                        2.219967385483012e+21, 2453443393512255500000.0, 2.711474287654572e+21, 2996642527825716300000.0, 3.311802173621677e+21, 3.660107448706394e+21,
                        4045044309342362300000.0, 4470465333012572700000.0, 4.940628276310861e+21
                      };
    double myw[801] = { 2.103562053838982e-29, -1.264469361608894e-14,
                        4.615731256788567e-14, -2.798703374257668e-14, 5.465764965410841e-14, -2.652933109928729e-14, 5.674913434067321e-14, -2.157276828977208e-14,
                        5.831846086773976e-14, -1.546589284868783e-14, 6.057302455652974e-14, -8.502531259083065e-15, 6.388018061147645e-14, -5.659657635010288e-16,
                        6.848500604791407e-14, 8.572897732168276e-15, 7.465068154681813e-14, 1.920837293261338e-14, 8.269345428975771e-14, 3.1701165629229e-14,
                        9.300004039695208e-14, 4.649069639417992e-14, 1.060441944490564e-13, 6.411216589597457e-14, 1.224060834001701e-13, 8.521776751507023e-14,
                        1.427957940487172e-13, 1.106026606968463e-13, 1.680820203098405e-13, 1.412367028159546e-13, 1.993271011776308e-13, 1.783032042964119e-13,
                        2.378298196799422e-13, 2.232462602765097e-13, 2.851776817107034e-13, 2.778285575785995e-13, 3.433107735233557e-13, 3.442019764139949e-13,
                        4.145997612327839e-13, 4.249938198224969e-13, 5.019411631949951e-13, 5.234121310773422e-13, 6.08873719324756e-13, 6.433743253810275e-13,
                        7.397205280796933e-13, 7.89664297886592e-13, 8.997626559623209e-13, 9.681243129571425e-13, 1.095451187471558e-12, 1.185889375491455e-12,
                        1.334666226164323e-12, 1.451673490118585e-12, 1.627033241780647e-12, 1.776119296526221e-12, 1.984309459865773e-12, 2.172225112712636e-12,
                        2.420855801356264e-12, 2.655866524621122e-12, 2.954213313000758e-12, 3.246433455110429e-12, 3.605807223054322e-12, 3.9676082798213e-12,
                        4.401806878720721e-12, 4.848316218220904e-12, 5.37417607788477e-12, 5.923886142128417e-12, 6.561955948855011e-12, 7.237468388830243e-12,
                        8.012831864792648e-12, 8.841766480402105e-12, 9.785047278800097e-12, 1.080115224902499e-11, 1.194974128877562e-11, 1.319424925552153e-11,
                        1.459380374689331e-11, 1.611708818260074e-11, 1.782336249944076e-11, 1.968696083966218e-11, 2.176804271234846e-11, 2.40471274537544e-11,
                        2.658616922424555e-11, 2.937256616666064e-11, 3.24711207158745e-11, 3.587699548548411e-11, 3.965909071112399e-11, 4.382145152220635e-11,
                        4.843856688602439e-11, 5.352476425684008e-11, 5.916190912377548e-11, 6.537635327328955e-11, 7.225949098391668e-11, 7.985185650562155e-11,
                        8.825697213255411e-11, 9.753221923111176e-11, 1.077963949370144e-10, 1.191270094182892e-10, 1.31661951905434e-10, 1.455028951566729e-10,
                        1.608114581091983e-10, 1.777184270673645e-10, 1.964147916871289e-10, 2.170665216346822e-10, 2.399008451839042e-10, 2.651263504640323e-10,
                        2.930148720448538e-10, 3.238267179640594e-10, 3.578885297833856e-10, 3.955234710219298e-10, 4.371254308993604e-10, 4.83094047393758e-10,
                        5.339056350072159e-10, 5.90052957369007e-10, 6.521132758098962e-10, 7.206928333934838e-10, 7.964924450372341e-10, 8.802567084675067e-10,
                        9.728375895186284e-10, 1.075148437456224e-09, 1.188226062693121e-09, 1.313189706258061e-09, 1.451302163665563e-09, 1.6039339435116e-09,
                        1.77262406329356e-09, 1.95904973321987e-09, 2.165087540667258e-09, 2.392789115986871e-09, 2.644443536014764e-09, 2.922559573439235e-09,
                        3.229930291248597e-09, 3.569622651576204e-09, 3.945045448172924e-09, 4.359947261255963e-09, 4.818489091363688e-09, 5.325251901762953e-09,
                        5.885315583343685e-09, 6.504277635547376e-09, 7.18834041924257e-09, 7.944342903082902e-09, 8.77985856295911e-09, 9.703242578022093e-09,
                        1.07237432276894e-08, 1.185156747840095e-08, 1.309800933225301e-08, 1.447553742402158e-08, 1.599794451372024e-08, 1.768046154055318e-08,
                        1.953993335487118e-08, 2.1594964684505e-08, 2.386612830616206e-08, 2.637614961034523e-08, 2.915015476269831e-08, 3.221590205565798e-08,
                        3.560407926098509e-08, 3.934859178954436e-08, 4.348692045365787e-08, 4.806047869438007e-08, 5.311504443749314e-08, 5.870120138001748e-08,
                        6.487486163571268e-08, 7.169780940885934e-08, 7.923833480505012e-08, 8.757190229426675e-08, 9.678192055835553e-08, 1.069605631204864e-07,
                        1.182097045925483e-07, 1.306419269237675e-07, 1.443816591198488e-07, 1.595664099835792e-07, 1.763481565722233e-07, 1.948948533650376e-07,
                        2.153921247351847e-07, 2.380451115468297e-07, 2.630805351444854e-07, 2.907489558998551e-07, 3.213272911558462e-07, 3.551215767529809e-07,
                        3.924700396067688e-07, 4.337464734078393e-07, 4.793639887921159e-07, 5.297791390370199e-07, 5.85496497998219e-07, 6.470737017046583e-07,
                        7.151270374758372e-07, 7.903376040582035e-07, 8.734581359370587e-07, 9.653205295304359e-07, 1.06684417629933e-06, 1.179045157323447e-06,
                        1.303046419382764e-06, 1.440089007182073e-06, 1.591544490556806e-06, 1.758928685376697e-06, 1.943916830388476e-06, 2.148360347694608e-06,
                        2.374305378111399e-06, 2.624013254094558e-06, 2.89998313729281e-06, 3.204977025773239e-06, 3.542047402097807e-06, 3.914567778667102e-06,
                        4.326266465748067e-06, 4.781263881007758e-06, 5.284113792545945e-06, 5.839848890150422e-06, 6.454031158395685e-06, 7.132807538712648e-06,
                        7.882971454044484e-06, 8.712030795792634e-06, 9.628283069078872e-06, 1.064089843325841e-05, 1.176001148348469e-05, 1.299682267761921e-05,
                        1.436371043746991e-05, 1.587435503282041e-05, 1.754387550120777e-05, 1.938898096105121e-05, 2.142813784487508e-05, 2.368175471430264e-05,
                        2.61723865181813e-05, 2.892496032668667e-05, 3.196702481167932e-05, 3.532902595927333e-05, 3.904461178455365e-05, 4.31509690875633e-05,
                        4.768919563102351e-05, 5.270471145419851e-05, 5.82477134493557e-05, 6.437367773954277e-05, 7.114391489568718e-05, 7.862618353777022e-05,
                        8.689536847209423e-05, 9.603423013681158e-05, .0001061342328695059, .0001172964602657162, .0001296326268075215, .0001432661958546299,
                        .00015833361521504, .0001749856826064412, .000193389054722159, .0002137279149064782, .0002362058162174614, .0002610477181410775,
                        .0002885022375064333, .0003188441357870562, .0003523770680013592, .0003894366200728159, .0004303936656695837, .0004756580748770003,
                        .0005256828130316798, .0005809684683619366, .0006420682561143772, .0007095935446942389, .0007842199637491256, .0008666941465924691,
                        .000957841183475901, .001058572843543458, .001169896665384001, .001292925974983324, .001428890965739396, .00157915088962763,
                        .001745207548623177, .001928720102656342, .002131521473093367, .002355636277673631, .002603300731229735, .002876984272542283,
                        .003179413630050106, .003513598723334281, .003882861625673649, .00429086725403169, .00474165797348686, .005239689338467119,
                        .005789870985188969, .00639760707200034, .007068843783102744, .007810112796625723, .008628584975720666, .009532112534855742,
                        .0105292869710523, .01162947042684567, .01284285301027502, .0141804540040849, .01565416842684913, .01727670025860997,
                        .01906157878467033, .02102295173845023, .02317553622087861, .02553413681316817, .02811347056705691, .03092716134472897,
                        .03398734108220733, .03730266904318316, .04087756584601726, .04470845458227711, .04878245655564208, .05307046388837388,
                        .05752521479656082, .06206888924914453, .06659098690582325, .07092687097703929, .07485762155329997, .07807466421172765,
                        .08018887211338042, .08067640670918658, .07891767306422777, .07412406301630496, .06545864753141331, .05195771725733346,
                        .03284797274184859, .00749707632583127, -.02386612869894549, -.06017494378476118, -.0981789979885067, -.1328147797272611,
                        -.1554628569772562, -.156398215798745, -.124304986652905, -.05486815986343697, .04686255899170307, .1511218295806206,
                        .2119315534410599, .1695134135887796, .0138619742033148, -.1869350451838135, -.2455889606925336, -.05309269401899814,
                        .2519998415798595, .1968224876057428, -.201433361896916, -.2458450827258603, .3433559314076636, -.04770066510626292,
                        -.2096628473507452, .2509085123794248, -.1676412661335192, .07495199786896763, -.01695135102751146, -.008828524201374996,
                        .0161678735618355, -.01556411755992529, .0125131112521637, -.009299315246978098, .006650525996779493, -.004667707408671884,
                        .003248885545556855, -.002255529108544675, .001566875211100915, -.001091132486368091, .0007625383049040949, -.0005352540577820409,
                        .000377710456721467, -.0002682528211535297, .0001920265274996755, -.0001388213723208944, .0001015998917810005, -7.549725062631259e-05,
                        5.714172920052936e-05, -4.419160967680634e-05, 3.501776199578583e-05, -2.84849695413999e-05, 2.380104817324115e-05, -2.041274924032166e-05,
                        1.79336348979186e-05, -1.609367780777977e-05, 1.470394692017765e-05, -1.363208540087839e-05, 1.278540851480116e-05, -1.209910323276592e-05,
                        1.152780746372085e-05, -1.103964249967709e-05, 1.061214724478712e-05, -1.022954672255804e-05, 9.880801917269063e-06, -9.558136268373164e-06,
                        9.255989462874843e-06, -8.97036803983496e-06, 8.698439226217636e-06, -8.438199899378174e-06, 8.188185039708096e-06, -7.947275976752668e-06,
                        7.714620489277085e-06, -7.489590334670121e-06, 7.271712845563131e-06, -7.06059520272004e-06, 6.85589095863429e-06, -6.657307826365352e-06,
                        6.464610635947412e-06, -6.277596705248834e-06, 6.096069004564178e-06, -5.919835014912806e-06, 5.748721389173238e-06, -5.582576428368341e-06,
                        5.421255729073172e-06, -5.26461148323362e-06, 5.112497827757443e-06, -4.964780650195476e-06, 4.821336526159266e-06, -4.682043530422997e-06,
                        4.546777587820041e-06, -4.415418000076004e-06, 4.287852503112911e-06, -4.163974668109847e-06, 4.043678407829827e-06, -3.926857526517075e-06,
                        3.813409851360361e-06, -3.703239239834851e-06, 3.596252927182967e-06, -3.492358600906126e-06, 3.391465179914198e-06, -3.29348543124194e-06,
                        3.198336356446399e-06, -3.105937110348406e-06, 3.016207679069661e-06, -2.929069911562291e-06, 2.844448954094881e-06, -2.762272935820411e-06,
                        2.682471568415877e-06, -2.604975709140556e-06, 2.529718233664062e-06, -2.456634690985054e-06, 2.385662793855871e-06, -2.316741584624232e-06,
                        2.249811415880699e-06, -2.184814552602377e-06, 2.121695378987067e-06, -2.0603999269499e-06, 2.00087543589398e-06, -1.943070483347481e-06,
                        1.886935339579619e-06, -1.832421953831803e-06, 1.779483599068986e-06, -1.728074671861562e-06, 1.67815084081871e-06, -1.629669220867866e-06,
                        1.582588274939725e-06, -1.536867577717458e-06, 1.492467744182388e-06, -1.449350544031671e-06, 1.407478963215944e-06, -1.366817091697906e-06,
                        1.327329980403758e-06, -1.288983628354532e-06, 1.251745052743577e-06, -1.215582289623042e-06, 1.180464297731392e-06, -1.146360878232118e-06,
                        1.113242681755176e-06, -1.081081241360643e-06, 1.049848946307979e-06, -1.019518969919736e-06, 9.900652269648073e-07, -9.614623823829486e-07,
                        9.336858590396267e-07, -9.067118039187765e-07, 8.805170379415897e-07, -8.550790335506564e-07, 8.303759185665738e-07, -8.063864695073603e-07,
                        7.830900795968434e-07, -7.604667251660013e-07, 7.384969528074763e-07, -7.171618775580271e-07, 6.964431695613518e-07, -6.763230273695452e-07,
                        6.567841555251206e-07, -6.378097555683096e-07, 6.193835199757372e-07, -6.014896169720738e-07, 5.841126695566173e-07, -5.672377400509635e-07,
                        5.508503223216395e-07, -5.349363333399711e-07, 5.194820986824491e-07, -5.044743364413132e-07, 4.899001458890472e-07, -4.757469999761242e-07,
                        4.620027360551677e-07, -4.486555431391317e-07, 4.356939495368206e-07, -4.231068139067277e-07, 4.108833178901058e-07, -3.990129570237777e-07,
                        3.874855299952715e-07, -3.762911289578004e-07, 3.654201320223786e-07, -3.54863196176586e-07, 3.44611248945519e-07, -3.346554794873414e-07,
                        3.249873307934947e-07, -3.15598493142124e-07, 3.06480897492867e-07, -2.976267081233949e-07, 2.890283152696976e-07, -2.806783286653362e-07,
                        2.725695717362821e-07, -2.646950756050221e-07, 2.570480727284082e-07, -2.496219907786807e-07, 2.424104471687142e-07, -2.354072438896643e-07,
                        2.286063621819694e-07, -2.220019570969968e-07, 2.155883523600859e-07, -2.093600356601861e-07, 2.033116540781646e-07, -1.974380094205501e-07,
                        1.917340535876188e-07, -1.861948842172547e-07, 1.808157405985162e-07, -1.755919996494557e-07, 1.705191718700136e-07, -1.655928973946416e-07,
                        1.608089422670497e-07, -1.561631948835526e-07, 1.516516624771349e-07, -1.472704676262496e-07, 1.430158448819191e-07, -1.388841375627619e-07,
                        1.348717946589134e-07, -1.309753677747614e-07, 1.271915081246862e-07, -1.235169636417206e-07, 1.19948576209994e-07, -1.16483278973208e-07,
                        1.131180936862105e-07, -1.098501281312535e-07, 1.066765736321394e-07, -1.035947026599537e-07, 1.006018664975167e-07, -9.769549295058651e-08,
                        9.487308412474973e-08, -9.21322142833144e-08, 8.947052777472484e-08, -8.688573700943116e-08, 8.437562048443172e-08, -8.193802086874367e-08,
                        7.957084315467929e-08, -7.727205286392825e-08, 7.50396742974787e-08, -7.287178883148888e-08, 7.07665332669298e-08, -6.872209823264986e-08,
                        6.673672663335082e-08, -6.48087121371678e-08, 6.293639770567428e-08, -6.111817417008917e-08, 5.935247885127626e-08, -5.763779421770836e-08,
                        5.597264657919956e-08, -5.435560481863042e-08, 5.278527916288309e-08, -5.126031999018991e-08, 4.977941667022704e-08, -4.83412964362335e-08,
                        4.694472329047102e-08, -4.558849694284832e-08, 4.427145178025873e-08, -4.299245586445184e-08, 4.175040995827635e-08, -4.054424658081963e-08,
                        3.937292909065092e-08, -3.823545079527342e-08, 3.713083408552377e-08, -3.605812959486601e-08, 3.501641538356351e-08, -3.400479614676831e-08,
                        3.302240244515663e-08, -3.206838995736202e-08, 3.114193875409117e-08, -3.024225259359901e-08, 2.936855823761587e-08, -2.852010478676213e-08,
                        2.769616303496246e-08, -2.689602484264953e-08, 2.611900252829978e-08, -2.53644282775314e-08, 2.463165356908288e-08, -2.39200486173057e-08,
                        2.322900183088905e-08, -2.255791928733344e-08, 2.190622422255186e-08, -2.127335653510145e-08, 2.065877230473273e-08, -2.006194332493974e-08,
                        1.948235664905881e-08, -1.891951414942437e-08, 1.837293208920017e-08, -1.784214070660012e-08, 1.732668381117887e-08, -1.682611839179446e-08,
                        1.634001423585344e-08, -1.586795355952947e-08, 1.540953064868929e-08, -1.496435151022419e-08, 1.453203353344868e-08, -1.411220516125227e-08,
                        1.370450557074419e-08, -1.330858436314438e-08, 1.292410126264865e-08, -1.25507258239834e-08, 1.218813714839246e-08, -1.183602360782992e-08,
                        1.149408257713515e-08, -1.116202017395058e-08, 1.083955100614394e-08, -1.0526397926519e-08, 1.022229179461678e-08, -9.926971245406734e-09,
                        9.640182464660921e-09, -9.361678970810806e-09, 9.091221403102824e-09, -8.828577315878212e-09, 8.573520978800616e-09, -8.325833182853652e-09,
                        8.085301051938885e-09, -7.851717859915976e-09, 7.624882852931747e-09, -7.404601076884107e-09, 7.190683209868762e-09, -6.982945399464102e-09,
                        6.781209104717332e-09, -6.585300942697731e-09, 6.395052539483568e-09, -6.210300385452473e-09, 6.030885694751333e-09, -5.8566542688268e-09,
                        5.68745636389964e-09, -5.523146562267662e-09, 5.36358364732565e-09, -5.208630482195534e-09, 5.058153891863612e-09, -4.912024548723426e-09,
                        4.77011686142501e-09, -4.63230886693463e-09, 4.498482125712853e-09, -4.368521619921419e-09, 4.242315654571151e-09, -4.119755761525383e-09,
                        4.000736606276379e-09, -3.885155897415073e-09, 3.772914298716528e-09, -3.663915343765296e-09, 3.558065353046999e-09, -3.455273353434971e-09,
                        3.355451000003056e-09, -3.258512500097394e-09, 3.164374539601736e-09, -3.072956211332787e-09, 2.984178945504153e-09, -2.897966442199276e-09,
                        2.814244605795313e-09, -2.732941481281439e-09, 2.653987192416816e-09, -2.577313881675167e-09, 2.502855651924429e-09, -2.430548509791296e-09,
                        2.360330310661908e-09, -2.292140705271406e-09, 2.22592108783654e-09, -2.161614545686758e-09, 2.09916581035045e-09, -2.038521210054267e-09,
                        1.979628623594711e-09, -1.922437435542387e-09, 1.866898492740427e-09, -1.812964062059653e-09, 1.760587789374176e-09, -1.709724659722168e-09,
                        1.660330958617607e-09, -1.61236423447973e-09, 1.565783262147887e-09, -1.520548007450427e-09, 1.476619592797189e-09, -1.433960263766035e-09,
                        1.39253335665469e-09, -1.352303266970005e-09, 1.313235418827548e-09, -1.275296235235242e-09, 1.238453109235514e-09, -1.202674375881138e-09,
                        1.167929285020692e-09, -1.13418797487023e-09, 1.101421446348478e-09, -1.069601538153474e-09, 1.038700902559248e-09, -1.008692981911727e-09,
                        9.795519858036666e-10, -9.51252868909002e-10, 9.2377130945756e-10, -8.97083688331633e-10, 8.711670687664494e-10, -8.459991766370928e-10,
                        8.215583813149323e-10, -7.978236770771082e-10, 7.74774665053093e-10, -7.523915356928136e-10, 7.306550517412669e-10, -7.095465317049981e-10,
                        6.890478337962292e-10, -6.69141340340839e-10, 6.498099426367938e-10, -6.310370262500165e-10, 6.128064567350563e-10, -5.951025657682865e-10,
                        5.779101376817111e-10, -5.612143963858077e-10, 5.450009926701687e-10, -5.29255991871025e-10, 5.139658618950525e-10, -4.991174615891697e-10,
                        4.846980294463296e-10, -4.706951726376001e-10, 4.570968563611062e-10, -4.438913934986793e-10, 4.310674345713248e-10, -4.186139579848742e-10,
                        4.065202605574395e-10, -3.947759483205284e-10, 3.833709275859127e-10, -3.722953962705749e-10, 3.615398354722752e-10, -3.510950012884991e-10,
                        3.409519168717552e-10, -3.311018647143929e-10, 3.215363791563124e-10, -3.12247239109124e-10, 3.032264609905071e-10, -2.944662918626933e-10,
                        2.859592027691788e-10, -2.77697882263937e-10, 2.696752301275724e-10, -2.61884351265013e-10, 2.543185497794985e-10, -2.469713232177689e-10,
                        2.398363569815098e-10, -2.329075189002498e-10, 2.261788539610461e-10, -2.196445791904288e-10, 2.132990786842053e-10, -2.071368987808525e-10,
                        2.011527433743496e-10, -1.953414693624216e-10, 1.896980822262837e-10, -1.842177317380848e-10, 1.788957077923634e-10, -1.737274363579317e-10,
                        1.687084755467094e-10, -1.638345117961281e-10, 1.591013561618254e-10, -1.545049407174433e-10, 1.500413150584345e-10, -1.457066429068751e-10,
                        1.414971988143619e-10, -1.374093649601637e-10, 1.334396280418735e-10, -1.295845762558885e-10, 1.258408963651246e-10, -1.222053708514437e-10,
                        1.186748751503467e-10, -1.152463749655566e-10, 1.119169236611821e-10, -1.08683659729222e-10, 1.055438043302322e-10, -1.024946589050432e-10,
                        9.953360285547503e-11, -9.665809129205519e-11, 9.386565284680683e-11, -9.115388754922578e-11, 8.852046476362457e-11, -8.596312118607507e-11,
                        8.347965889923978e-11, -8.10679434834466e-11, 7.872590218244558e-11, -7.645152212241484e-11, 7.424284858301879e-11, -7.209798331980772e-11,
                        7.001508293831719e-11, -6.79923573226507e-11, 6.60280681269051e-11, -6.412052735069306e-11, 6.226809604991307e-11, -6.046918330329692e-11,
                        5.872224571634798e-11, -5.702578811834639e-11, 5.537836697680089e-11, -5.377860007122251e-11, 5.222519065363231e-11, -5.07169852052075e-11,
                        4.925310917157278e-11, -4.783328375532226e-11, 4.645856316442775e-11, -4.513304831495452e-11, 4.386786828115582e-11, -4.269042848860555e-11,
                        4.166589074066043e-11, -4.09470613197253e-11, 4.089025606285087e-11, -4.232439520086882e-11, 4.71759702866184e-11, -5.992051472297203e-11,
                        9.095360729014628e-11
                      };

    myx_.resize(801);
    myx_.fill(myx);
    myw_.resize(801);
    myw_.fill(myw);
}

DC1dModellingC::DC1dModellingC(size_t nlayers,
               const RVector & am, const RVector & an,
               const RVector & bm, const RVector & bn, bool verbose)
: DC1dModelling(nlayers, am, an, bm, bn, verbose){
    setMesh(createMesh1DBlock(nlayers, 2));
}

DC1dModellingC::DC1dModellingC(size_t nlayers,
                               const RVector & ab2,
                               const RVector & mn2, bool verbose)
: DC1dModelling(nlayers, ab2, mn2, verbose){
    setMesh(createMesh1DBlock(nlayers, 2));
}

RVector DC1dModellingC::response(const RVector & model) {
    if (model.size() < (nlayers_ * 3 - 1)){
        throwError(WHERE_AM_I + " model vector to small: nlayers_ * 3 - 1 = " + str(nlayers_ * 3 - 1) + " > " + str(model.size()));
    }
    if (model.size() > (nlayers_ * 3 - 1)){
        throwError(WHERE_AM_I + " model vector to large: nlayers_ * 3 - 1 = " + str(nlayers_ * 3 - 1) + " < " + str(model.size()));
    }

    RVector thk(model(0,               nlayers_ -1));
    RVector rhoM(model(nlayers_ - 1,    2 * nlayers_ -1));
    RVector rhoP(- model(2 * nlayers_ -1, 3 * nlayers_ -1));

//     for (size_t i = 0 ; i < nlayers_ -1 ; i++) thk[i] = model[i];
//     for (size_t i = 0 ; i < nlayers_ ; i++) rhoM[i] = model[nlayers_ + i -1];
//     for (size_t i = 0 ; i < nlayers_ ; i++) rhoP[i] = - model[2 * nlayers_ + i -1];
    CVector rhoC = toComplex(RVector(rhoM * cos(rhoP)), -RVector(rhoM * sin(rhoP)));

    CVector rhoaC = rhoaT< CVector >(rhoC, thk);
    RVector angPlus = angle(rhoaC);
    //RVector angPlus = abs(angle(rhoaC));

    return cat(abs(rhoaC), angPlus);
}

} // namespace GIMLI{
